package com.ruoyi.system.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.system.order.domain.AfterSale;
import com.ruoyi.system.order.domain.AfterSaleDetailDTO;
import com.ruoyi.system.order.domain.AfterSaleHistory;
import com.ruoyi.system.order.mapper.AfterSaleHistoryMapper;
import com.ruoyi.system.order.service.AfterSaleService;
import com.ruoyi.system.order.mapper.AfterSaleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author lenovo
* @description 针对表【after_sale(售后主表)】的数据库操作Service实现
* @createDate 2025-07-10 15:04:58
*/
@Service
public class AfterSaleServiceImpl extends ServiceImpl<AfterSaleMapper, AfterSale>
    implements AfterSaleService{
    @Autowired
    private AfterSaleHistoryMapper historyMapper;

    @Override
    public AfterSaleDetailDTO getDetailByOrderId(Long orderId) {
        LambdaQueryWrapper<AfterSale> query = new LambdaQueryWrapper<>();
        query.eq(AfterSale::getOrderId, orderId);
        AfterSale afterSale = this.getOne(query);

        if (afterSale == null) {
            return null;
        }

        List<AfterSaleHistory> historyList = historyMapper.selectList(
                new LambdaQueryWrapper<AfterSaleHistory>()
                        .eq(AfterSaleHistory::getAfterSaleId, afterSale.getId())
        );

        AfterSaleDetailDTO dto = new AfterSaleDetailDTO();
        dto.setAfterSale(afterSale);
        dto.setHistoryList(historyList);
        return dto;
    }
}




